/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataAccess.session;


//import javax.ejb.Stateless;
import DataAccess.entity.Categoriaprodotto;
import DataAccess.entity.Prodotto;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Domenico
 */
//@Stateless
public class ProdottoFacade extends AbstractFacade<Prodotto> {
    @PersistenceContext(unitName = "ProgettoDe_COPU")
    private EntityManager em;

    //@Override
    //protected EntityManager getEntityManager() {
    //    return em;
    //}

    public ProdottoFacade() {
        super(Prodotto.class);
    }
    // manually created
    public List<Prodotto> findForCategoria(Categoriaprodotto categoria) {
        
        Query q = getEntityManager().createQuery("SELECT p FROM Prodotto p WHERE p.categoria = :categoria");
        q.setParameter("categoria", categoria.getIdCategoriaprodotto());
        
        return q.getResultList();
        
    }
}
